// pages/home-school-export-student/home-school-export-student.ts
interface GroupHeader {
  teacher: string,
  avatar: string,
  groupName: string,
  startTime: string,
  endTime: string,
  group: Group[]
}
interface Group {
  index: string,
  groupMember: {
    index: string,
    groupMember: {
      name: string,
      homework: boolean
    }
  },
}
Page({

  /**
   * 页面的初始数据
   */
  data: {
    search: "",
    listData: [] as Group[],
  },
  handleClick(e: any) {
    const { name } = e.currentTarget.dataset
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    prevPage.setData({
      student: name
    })
    wx.navigateBack({
      delta: 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    wx.request({
      url: "https://mock.presstime.cn/mock/656dbe322fef936d34630d40/yi-xiao-ping/home-school-group",
      success: (res: {
        data: {
          data: any,
          code: number
        }
      }) => {
        const { data } = res;
        const { data: groupData, code } = data
        if (code === 200) {
          const { group } = groupData
          this.setData({
            listData: group,
          })
        }
      }
    })
  },
  handleSearch(e: any) {
    const { value } = e.detail
    this.setData({
      search: value
    })
    wx.request({
      url: "https://mock.presstime.cn/mock/656dbe322fef936d34630d40/yi-xiao-ping/home-school-group",
      data: {
        search: value
      },
      success: (res: {
        data: {
          data: any,
          code: number
        }
      }) => {
        const { data } = res;
        const { data: groupData, code } = data
        if (code === 200) {
          this.setData({
            groupHeader: groupData
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})